home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_11 / a11_2.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  1.8 KB  |  66 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 11.2 (Shifted Inverse Power Method).
  9. % Section    11.2,    The Power Method, Page 558
  10. echo on; clc; format long; hold off; clear
  11.  
  12. %     INVERSE POWER METHOD FOR FINDING AN EIGEN-PAIR
  13.  
  14. %     Assume that A is an n by n real matrix and that it
  15.  
  16. % has a full set of eigenvectors  V , V  ,..., V .
  17. %                                  1   2        n
  18.  
  19. % The shifted inverse power method of iteration is used to find an
  20.  
  21. % eigenvalue and its corresponding eigenvector. Iteration will continue
  22.  
  23. % until each coordinate of the eigenvector has converged with an
  24.  
  25. % error less than epsilon or the iteration limit is reached.
  26.  
  27. % Remark. invpow.m lufact.m lusolv.m are used for Algorithm 11.2
  28.  
  29. pause % Press any key to continue.      
  30.  
  31. clc;
  32.  
  33. % Place the matrix in  A
  34. % Place the shift  in  alpha
  35. % Place the starting vector in  X
  36. % Place the tolerance in   epsilon
  37. % Place the maximum number of iterations in  max1
  38.  
  39. A = [ 0    11    -5;
  40.      -2    17    -7;
  41.      -4    26   -10];
  42.  
  43. [n,n] = size(A);
  44. X = ones(n,1);
  45.  
  46. alpha = 4.2;
  47.  
  48. epsilon = 1e-14;
  49. max1 = 50;
  50.  
  51. [lambda,V] = invpow(A,alpha,X,epsilon,max1,1);
  52.  
  53. pause % Press any key to continue.
  54.  
  55. Mx1 = 'Implementation of the shifted inverse power method.';
  56. Mx2 = 'The matrix  A  is: '
  57. Mx3 = 'The initial shift was  alpha = ';
  58. Mx4 = [Mx3,num2str(alpha)];
  59. Mx5 = 'The desired eigenvalue of  A  is: ';
  60. Mx6 = 'The desired eigenvector of  A  is: ';
  61. clc,echo off,diary output,...
  62. disp(''),disp(Mx1),disp(''),disp(Mx2),disp(A),...
  63. disp(''),disp(Mx4),disp(''),...
  64. disp(Mx5),disp(lambda),disp(Mx6),disp(V),...
  65. diary off,echo on
  66.